package all.multi;

import leetcodeHis.ListNode;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author by zhangleishuidihuzhu.com
 * @Date 2023/5/26 14:46
 */
public class Test0526 {

    public static void main(String[] args) {
//        Scanner scanner = new Scanner(System.in);
//
//        while (scanner.hasNext()) {
//            String a = scanner.next();
//            System.out.println(a);
//        }

        Test0526 t = new Test0526();

        System.out.println(t.jinzhi("0x8000FFFF"));
    }




    /**
     * 16进制转10进制
     */
    private String jinzhi(String num) {
        //先将 0x过滤， 然后每个数字 x 16
        char[] arr = num.toCharArray();
        long result = 0;
        for (int i = 2; i < arr.length; i++) {
            char cur = arr[i];
            if('A' == cur) {
                result = result*16 + 10;
            }else if('B' == cur) {
                result = result*16 + 11;
            }else if('C' == cur) {
                result = result*16 + 12;
            }else if('D' == cur) {
                result = result*16 + 13;
            }else if('E' == cur) {
                result = result*16 + 14;
            }else if('F' == cur) {
                result = result*16 + 15;
            }else {
                result = result*16 + (cur - '0');
            }
        }
        return result+"";
    }


    /**
     * 汽水瓶
     * @param arr
     * @return
     */
    private int[] bubble(int[] arr) {
        // 3个可换一个， 剩两个可借一个， 剩一个结束
        int[] result= new int[arr.length];
        for (int i = 0; i < arr.length; i++) {
            result[i] = compute(arr[i]);
        }
        return result;
    }

    private int compute(int i) {
        int result = 0;
        while (i>1) {
            if(i == 2) {
                result++;
                break;
            }
            int cur = i/3;
            i = i%3 + cur;
            result += cur;
        }
        return result;
    }

    /**
     * {1,2,3,4,5,-1,6}
     * 一个整型数组，求子数组的和的最大值
     */
    private int maxValue(int[] arr) {
        if(arr.length == 0) {
            return 0;
        }
        int[] result = new int[arr.length];

        result[0] = arr[0];
        for (int i = 1; i < arr.length; i++) {
            result[i] = Math.max(arr[i], arr[i]+result[i-1]);
        }

        int max = result[0];
        for (int i = 1; i < result.length; i++) {
            max = Math.max(max, result[i]);
        }
        return max;
    }

    /**
     * 两个升序链表  合并为一个降序链表
     * @return
     */
    private ListNode merge(ListNode listNode1, ListNode listNode2) {
        ListNode head1 = listNode1;
        ListNode head2 = listNode2;

        ListNode head = new ListNode(-1);
        ListNode cur = head;
        while (head1 != null || head2 != null) {
            if(head1 == null) {
                cur.next = head2;
                break;
            }
            if(head2 == null) {
                cur.next = head1;
                break;
            }

            if(head1.val < head2.val) {
                cur.next = head1;
                head1 = head1.next;
                cur = cur.next;
            }else {
                cur.next = head2;
                head2 = head2.next;
                cur = cur.next;
            }
        }

        return reverse(head.next);
    }

    private ListNode reverse(ListNode head) {
        ListNode cur = head;
        ListNode pre = null;

        while (cur!=null) {
            ListNode next = cur.next;
            cur.next = pre;
            pre = cur;
            cur = next;
        }

        return pre;
    }
}
